package com.sky.controller.user;

import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.web.bind.annotation.*;

@RestController("userShopController")
@Slf4j
@Api("店铺相关接口")
@RequestMapping("/user/shop")
public class ShopController {
    public static final String ShopStatus="shop_status";

    @Autowired
    RedisTemplate redisTemplate;


    @PutMapping("/{status}")
    @ApiOperation("修改营业状态")
    public Result setStatus(@PathVariable Integer status){
        log.info("修改营业状态为{}", status==1 ? "营业中" : "打样中");
        ValueOperations valueOperations = redisTemplate.opsForValue();
        valueOperations.set(ShopStatus, status);
        return Result.success();
    }
    @GetMapping("/status")
    @ApiOperation("获取营业状态")
    public Result<Integer> getStatus(){
        ValueOperations valueOperations = redisTemplate.opsForValue();
        Integer status = (Integer) valueOperations.get(ShopStatus);
        log.info("营业状态为{}",status==1 ? "营业中" : "打烊中");
        return Result.success(status);
    }
}
